<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <style>
    .wrap {
      width: 1072px;
      height: 400px;
      margin: 50px auto;
    }

    .wrap img {
      float: left;
      border: 1px solid black;
      margin-right: 20px;
    }

    .top {
      float: left;
      width: 600px;
      height: 220px;
      border-bottom: 1px solid #bbb;
      font-family: 'Microsoft yahei';
    }

    .top p span {
      font-size: 14px;
      color: .666;
      border: 1px solid #999;
      display: inline-block;
      padding: 8px;
      cursor: pointer;
    }

    .top p span.on {
      border: 2px solid #f60;
      padding: 7px;
      background: url(images/on.png) no-repeat right bottom;
    }
  </style>
</head>

<body>
  <div class="wrap">
    <img src="images/black.jpg" alt="">
    <div class="top">
      <p class="color">
        <label class="">颜色</label>
        <span class="on" data-index="0">黑色</span>
        <span class="" data-index="1">白色</span>
        <span class="" data-index="2">红色</span>
        <span class="" data-index="3">黄色</span>
        <span class="" data-index="4">紫色</span>
        <span class="" data-index="5">绿色</span>
      </p>
      <p class="rom">
        <label class="">内存</label>
        <span class="on">64GB</span>
        <span class="">128GB</span>
        <span class="">256GB</span>
      </p>
      <p class="banben">
        <label>版本</label>
        <span class="on">全网通</span>
        <span>移动版</span>
        <span>联通版</span>
        <span>电信版</span>
      </p>
    </div>

  </div>


  <script>
    const imgArr = ['images/black.jpg', 'images/white.jpg', 'images/red.jpg', 'images/yellow.jpg', 'images/purple.jpg', 'images/green.jpg'];
    const color = document.querySelector('.color')
    const rom = document.querySelector('.rom')
    const banben = document.querySelector('.banben')
    color.addEventListener('click', function (e) {
      if (e.target.localName === 'span') {
        document.querySelector('.color span.on').classList.remove('on')
        e.target.classList.add('on')
        document.querySelector('.wrap img').src = imgArr[e.target.dataset.index]
      }
    })
    rom.addEventListener('click', function (e) {
      document.querySelector('.rom span.on').classList.remove('on')
      e.target.classList.add('on')
    })
    banben.addEventListener('click', function (e) {
      document.querySelector('.banben span.on').classList.remove('on')
      e.target.classList.add('on')
    })
  </script>

</body>

</html>